package gamehistory;

import gamehistory.utils.xml.XMLModel;
import scg.gen.AccountAcceptTrans;
import scg.gen.AccountRefundTrans;
import scg.gen.AccountSolveTrans;
import scg.gen.Event;
import scg.gen.History;
import scg.gen.PlayerKickedEvent;
import scg.gen.PlayerTrans;
import scg.gen.Round;

/**
 * 
 * @author Brent Kersanske
 *
 */
public abstract class HistoryAssimilation {
	
	protected XMLModel assimilatedModel;

	/**
	 * 
	 * @param assimilationName
	 */
	public HistoryAssimilation(String assimilationName) {
		this.assimilatedModel = new XMLModel(assimilationName);
	}
	
	public XMLModel getModel() {
		buildXMLModel();
		return this.assimilatedModel;
	}
	
	/**
     * 
     * @param gameHistory
     */
    protected void assimilate(History gameHistory) {         
        for(Round gameRound : gameHistory.getRounds()) {
            int roundNumber = gameRound.getNum();
            for(Event event : gameRound.getTrans()) {
                if(event instanceof AccountAcceptTrans) {
                        handleAccountAcceptTransaction(roundNumber, ((AccountAcceptTrans)event));
                } else if(event instanceof AccountSolveTrans) {
                        handleAccountSolveTransaction(roundNumber, ((AccountSolveTrans)event));
                } else if(event instanceof AccountRefundTrans) {
                        handleAccountRefundTransaction(roundNumber, ((AccountRefundTrans)event));
                } else if(event instanceof PlayerTrans) {
                        handlePlayerTransactions(roundNumber, ((PlayerTrans)event));
                } else if(event instanceof PlayerKickedEvent) {
                        handlePlayerKicked(((PlayerKickedEvent) event));
                }
            }
        }
    }
    
    /**
     * 
     * @param roundNumber
     * @param playerTrans
     */
    protected abstract void handlePlayerTransactions(int roundNumber, PlayerTrans playerTrans);

    /**
     * 
     * @param playerKickedEvent
     */
    protected abstract void handlePlayerKicked(PlayerKickedEvent playerKickedEvent);

    /**
     * 
     * @param accountRefundTrans
     */
    protected abstract void handleAccountRefundTransaction(int roundNumber, AccountRefundTrans accountRefundTrans);

    /**
     * 
     * @param accountSolveTrans
     */
    protected abstract void handleAccountSolveTransaction(int roundNumber, AccountSolveTrans accountSolveTrans);

    /**
     * 
     * @param accountAcceptTrans
     */
    protected abstract void handleAccountAcceptTransaction(int roundNumber, AccountAcceptTrans accountAcceptTrans); 
    
    /**
     * 
     */
    protected abstract void buildXMLModel();
    
    /**
     * 
     * @return
     */
    protected abstract String getAssimilationType();
    
    /**
     * 
     * @return
     */
    public abstract String retrieveFileOutName();
}
